<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!-- 作习时间表 -->
<div class="widget-box" style="margin:0 auto;">
	<div class="widget-header widget-header-flat">
		<b>学校作习时间表</b>
	</div>
	<div class="widget-body" style="min-height:600x;"> 
		<table class="table table-striped table-hover table-bordered" id="class_learnTime_table">
		    <tr id="fristTr" style="display:none;"><td></td><td></td><td></td></tr>
		 	<tr>
		 		<td width="33%">
		 		开始时间：<input type="text"  name="class_leartTime_start" require='true'  meth="isTime0945" maxlength="5" title="课排时间格式为9:30,注意:号的格式">
		 		</td>
		 		<td width="33%">
		 		结束时间：<input type="text" name="class_leartTime_end" require='true'  meth="isTime0945" maxlength="5" title="课排时间格式为10:30,注意:号的格式">
		 		</td>
		 		<td width="33%">
		 		事项：<input type="text" name="class_leartTime_vluae"  maxlength="20"><img alt="" name="class_learnTime_table_add" src="${pageContext.request.contextPath}/image/jia.png"><img alt="" name="class_learnTime_table_delete" src="${pageContext.request.contextPath}/image/jian.png">
		 		</font> 
		 		</td>
		 	</tr> 
		 	<tr>
		 		<td colspan="2">
		 			<button id="id-btn-savelearTime" class="btn btn-sm btn-primary">保存<font></font>课排表</button>
		 		</td>
		 	</tr>
		 </table>   				  
	</div>
</div>
<script>
(function(){
		var ac = function(){
			$(this).parent().parent().remove();
		}
	    var bc =function(){ 
		var content='<tr>'+
		 		'<td width="33%">'+
			 		'开始时间：<input type="text"  name="class_leartTime_start"  require="true"  meth="isTime0945" maxlength="5" title="课排时间格式为09:30,注意:号的格式(24小时制)">'+
			 		'</td>'+
			 		'<td width="33%">'+
			 		'结束时间：<input type="text" name="class_leartTime_end"  require="true"  meth="isTime0945" maxlength="5" title="课排时间格式为9:30,注意:号的格式(24小时制)">'+
			 		'</td>'+
			 		'<td width="33%">'+
			 		'事项：<input type="text" name="class_leartTime_vluae" maxlength="20">'+
			 			  '<img alt="" name="class_learnTime_table_add" src="${pageContext.request.contextPath}/image/jia.png">'+
			 			  '<img alt="" name="class_learnTime_table_delete" src="${pageContext.request.contextPath}/image/jian.png">'+
			 		'</font> '+
			 		'</td>'+
				'</tr> ';
			$(this).parent().parent().after(content);
			$("img[name=class_learnTime_table_add]").unbind("click").click(bc);
			$("img[name=class_learnTime_table_delete]").click(ac);
		};
		//加载事件
		$("img[name=class_learnTime_table_add]").unbind("click").click(bc);
		$("img[name=class_learnTime_table_delete]").click(ac);
		//存入数据库
		$("#id-btn-savelearTime").click(function(){
			var a =$("#class_learnTime_table").hzValidate("init");  
			if(a==false){
				return;
			}
			var start =$("input[name=class_leartTime_start]");
			var end =$("input[name=class_leartTime_end]");
			var value=$("input[name=class_leartTime_vluae]");
			var arr=new Array();
			for(var i=0;i<start.length;i++){ 
				var object={};
				object.start=$(start[i]).val();
				object.end=$(end[i]).val();
				object.value=$(value[i]).val();
				var kb =false;
				for(var j=0;j<arr.length;j++){
					var jb =arr[j];
					if(jb.start == object.start && jb.end ==object.end){
						kb=true;break;
					}
				}
				if(kb==false){
					arr.push(object);
				}
			}  
			var url ="${pageContext.request.contextPath}/edu/sysClassAction.do?method=updateClassLreanTime&r="+Math.random();
			$.ajax({
				   type: "POST",
				   url: url,
				   data: {table_id:"${param.table_id}",timeLearn:obj2str(arr)},
				   dataType:'json',
				   success: function(msg){
					   alert(msg.message); 
				   }
				});
		}); 
		//加载数据
		function loadLearnTime(){
			var url ="${pageContext.request.contextPath}/edu/sysClassAction.do?method=getClassLreanTime&r="+Math.random();			
				$.ajax({
				   type: "POST",
				   url: url,
				   data: {table_id:"${param.table_id}"},
				   dataType:'json',
				   success: function(msg){  
					    
					  if(msg){ 
						  var arr = eval(msg.timeLearn); 
						  var content="";
						  for(var i=0;i<arr.length;i++){
							   content+='<tr>'+
						 		'<td width="33%">'+
							 		'开始时间：<input type="text"  name="class_leartTime_start"  require="true" value="'+arr[i].start+'"  meth="isTime0945" maxlength="5" title="课排时间格式为9:30,注意:号的格式">'+
							 		'</td>'+
							 		'<td width="33%">'+
							 		'结束时间：<input type="text" name="class_leartTime_end"  require="true"  value="'+arr[i].end+'"  meth="isTime0945" maxlength="5" title="课排时间格式为9:30,注意:号的格式">'+
							 		'</td>'+
							 		'<td width="33%">'+
							 		'事项：<input type="text" name="class_leartTime_vluae"  value="'+arr[i].value+'" maxlength="20">'+
							 			  '<img alt="" name="class_learnTime_table_add" src="${pageContext.request.contextPath}/image/jia.png">'+
							 			  '<img alt="" name="class_learnTime_table_delete" src="${pageContext.request.contextPath}/image/jian.png">'+
							 		'</font> '+
							 		'</td>'+
								'</tr> '; 
						  }
						  $("#fristTr").after(content);
						  $("img[name=class_learnTime_table_add]").unbind("click").click(bc);
						  $("img[name=class_learnTime_table_delete]").click(ac);
					  }
				   }
				});
			
		}
		$(function(){
			loadLearnTime();
		});
})();
</script>